package com.encyclopedia.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.encyclopedia.entity.Plant;
import com.encyclopedia.service.PlantService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/plant/plant")
public class PlantController {
    @Autowired
    private PlantService plantService;

    @GetMapping("/plantByName")
    public List<Plant> plantByName(@Param("name") String name) {
        return plantService.ByName(name);
    }

    @GetMapping("/plantByGenusId")
    public List<Plant> plantByGenusId(@Param("genusId") Integer genusId) {
        return plantService.ByGenusId(genusId);

    }

    @GetMapping("/plantById")
    public Plant plantByBreedId(@Param("plantId") Integer plantId) {
        return plantService.ById(plantId);
    }


    @GetMapping("/getPlantByGenusName")
    public List<Plant> getPlantByGenusName(String genusName) {
        return plantService.getPlantByGenusName(genusName);
    }

    @GetMapping("/getPlantByFamilyName")
    public List<Plant> getPlantByGenusId(@Param("familyName") String familyName) {
        return plantService.getPlantByFamilyName(familyName);

    }

    @GetMapping("/getPlantAll")
    public Page<Plant> getPlantAll(@Param("current") Integer current) {
        return plantService.getPlantAll(current);
    }

    /**
     * 查看主页时默认显示当前月份适合种植的植物的植物
     */
    @GetMapping("/plantByMonth")
    public List<Plant> plantByMonth(@Param("month") Integer month) {
        return plantService.getPlantByMonth(month);
    }


}
